<ul class="categories_parent">
   <?
   $product_categories = product_cat(0);
   foreach($product_categories as $cat){
      $product_categories_child = product_cat($cat['cat_id']);
   ?>
      <li class="categories_parent_li">
         <a href="<?=generate_service_cat_url($cat)?>"><?=$cat['cat_name']?></a>
            <?if($product_categories_child != NULL){?>
               <ul class="categories_child">
            <?
            foreach($product_categories_child as $cat_child){
               $product_categories_child_child = product_cat($cat_child['cat_id']);
            ?>
            
               <li class="categories_child_li">
                  <a href="<?=generate_service_cat_url($cat_child)?>" class="<?=($product_categories_child_child  != NULL) ? 'has_child':''?>"><?=$cat_child['cat_name']?></a>
                  <?if($product_categories_child_child  != NULL){
                     ?>
                     <ul class="categories_child_child" style="display: none;">
                     <?
                     foreach($product_categories_child_child as $cat_child_child){
                  ?>
                     
                         <li class="categories_child_child_li">
                           <a href="<?=generate_service_cat_url($cat_child_child)?>"><?=$cat_child_child['cat_name']?></a>
                           
                         </li>
                         <? } ?>
                     </ul>
                  <? }?>
               </li>
               <? } ?>
            </ul>
         <? } ?>
      </li>
   <? } ?>
   </ul>